package leetcode;

/**
 * @Project : AlgorithmLearning
 * @Package : Leetcode
 * @File : Q1047.java
 * @Author : WangRuoyu
 * @Date 2023/11/9 17:13
 */


public class Q1047 {
    public String removeDuplicates(String s) {
        StringBuilder stack = new StringBuilder(s.length());
        for (int i = 0; i < s.length(); i++) {
            if (stack.isEmpty() || stack.charAt(stack.length() - 1) != s.charAt(i)) {
                stack.append(s.charAt(i));
            } else {
                stack.deleteCharAt(stack.length() - 1);
            }
        }
        return stack.toString();
    }

    public static void main(String[] args) {
        Q1047 sl = new Q1047();
        String s = "abbaca";
        System.out.println(sl.removeDuplicates(s));
    }
}